import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';

import { BlogArticle } from '../../class/blog-article';
import { BlogService } from '../../service/blog.service';

declare var $: any;

@Component({
  selector: 'app-blog-detail',
  templateUrl: './blog-detail.component.html',
  styleUrls: ['./blog-detail.component.css']
})
export class BlogDetailComponent implements OnInit {
  // 文章
  article: BlogArticle = new BlogArticle();
  // 编辑器实例
  ckeditor: any;

  constructor(
    private route: ActivatedRoute,
    private blogService: BlogService
  ) { }

  ngOnInit() {
    let bindThis = this;
    this.getArticle();
  }
  /** 
   * 获取文章
   */
  getArticle(): void {
    let bindThis = this;
    const id = bindThis.route.snapshot.paramMap.get('id');
    this.blogService.queryArticleById(Number(id), (result) => {
      if (result.code == "200") {
        bindThis.article = result.data;
        $(".article-content").html(result.data.articleContent);
        $(".article-content img").css("max-width", "90%");
        $(".article-content img").css("height", "auto");
      }
    });
  }
}
